<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix"><span>秒杀</span></div>
    <div class="bds">
      <el-collapse v-model="activeName">
        <el-collapse-item title="组件样式" name="c0">
          <el-form size="medium" label-width="100px">
            <el-form-item label="内容布局">
              <el-radio-group size="small" v-model="data.type">
                <el-radio :label="'item_one'">单列</el-radio>
                <el-radio :label="'item_two'">双列</el-radio>
                <el-radio :label="'item_three'">列表</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="背景色"><ColorPicker :color="data.color" :name="'bg'"></ColorPicker></el-form-item>
          </el-form>
        </el-collapse-item>
        <el-collapse-item title="添加直播间" name="c1">
          <el-form size="medium" label-width="100px">
            <el-form-item label="选择直播间">
              <el-radio-group size="small" v-model="data.showtype">
                <el-radio :label="1">自动选择</el-radio>
                <el-radio :label="2">手动选择</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-form>
          <div class="proSelect" v-if="data.showtype == 2">
            <div class="phead">
              <div class="name">商品</div>

              <div class="action">操作</div>
            </div>
            <ul>
              <draggable element="ul" v-model="data.list" :animation="500">
                <li v-for="(item, i) in data.list" :key="i">
                  <div class="dragIcon"><i class="el-icon-d-caret"></i></div>
                  <div class="pro">
                    <vimage style="width: 40px; height: 40px" :src="item.cover_img" fit="fit"></vimage>
                    <div class="txt">{{ item.title }}</div>
                  </div>

                  <div class="action"><el-button type="text" @click="remove(i)">删除</el-button></div>
                </li>
              </draggable>
              <li class="addPro" @click="addlive"><el-button type="text">添加直播间</el-button></li>
              <!-- <li class="addPro" v-if="data.type == 2" @click=""><el-button type="text">选择分组</el-button></li> -->
            </ul>
          </div>
        </el-collapse-item>
        <el-collapse-item title="基本样式" name="c1">
          <el-form size="medium" label-width="100px">
            <el-form-item label="上间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.top"></el-slider>
                <el-input-number v-model="data.margin.top" :controls="false" :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="下间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.bottom"></el-slider>
                <el-input-number v-model="data.margin.bottom" :controls="false" :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="左右间距">
              <div class="slider_box">
                <el-slider class="slider_item" :max="20" v-model="data.margin.lr"></el-slider>
                <el-input-number v-model="data.margin.lr" :controls="false" :min="0" :max="20"></el-input-number>
              </div>
            </el-form-item>

            <el-form-item label="上边角">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.radius.top"></el-slider>
                <el-input-number v-model="data.radius.top" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
            <el-form-item label="下边角">
              <div class="slider_box">
                <el-slider class="slider_item" :max="50" v-model="data.radius.bottom"></el-slider>
                <el-input-number v-model="data.radius.bottom" :controls="false" :min="0" :max="50"></el-input-number>
              </div>
            </el-form-item>
          </el-form>
        </el-collapse-item>
      </el-collapse>
    </div>
    <el-dialog title="选择直播间" :visible.sync="showSelect" width="50%" append-to-body><SelectLive :data="selectPro" @outData="closelive"></SelectLive></el-dialog>
  </el-card>
</template>

<script>
import ColorPicker from '@/components/ColorPicker/index';
import SelectLive from '@/components/SelectLive/index';
import draggable from 'vuedraggable';

export default {
  data() {
    return {
      activeName: ['c0', 'c1'],
      selectPro: [],
      showSelect: false
    };
  },
  props: {
    data: {
      type: Object,
      default: {}
    }
  },
  components: {
    ColorPicker,
    SelectLive,
    draggable
  },

  methods: {
    addlive() {
      this.selectPro = this.data.list;
      this.showSelect = true;
    },
    closelive(data) {
      this.data.list = data;
      this.showSelect = false;
    },
    remove(i) {
      this.data.list.splice(i, 1);
    }
  }
};
</script>
<style lang="scss">
.proSelect {
  width: 100%;
  border: 1px solid #dcdfe6;
  margin-bottom: 22px;

  .phead {
    background: #f4f6f8;
    font-weight: 700;
    display: flex;
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #dcdfe6;

    .name {
      flex: 1;
      padding-left: 10px;
    }

    .price {
      width: 80px;
      text-align: center;
    }

    .action {
      width: 100px;
      text-align: center;
    }
  }

  ul {
    margin: 0;

    li {
      display: flex;
      cursor: pointer;
      line-height: 40px;
      padding: 10px 0;
      font-size: 13px;
      border-bottom: 1px solid #dcdfe6;

      // &:last-child{
      //   border-bottom: none;
      // }

      &.addPro {
        display: block;
        width: 100%;
        box-sizing: border-box;
        text-align: center;
        border-bottom: none;
      }

      .dragIcon {
        width: 40px;
        height: 40px;
        text-align: center;
        font-size: 16px;
      }

      .pro {
        display: flex;
        flex: 1;

        .txt {
          display: flex;
          padding-left: 10px;
          flex: 1;
          line-height: 18px;
          align-items: center;

          .mark {
            color: #f56c6c;
            background: #f2f4f6;
            display: table;
            border-radius: 5px;
            padding: 0 3px;
            margin-right: 3px;
          }
        }
      }

      .price {
        width: 80px;
        text-align: center;
      }

      .action {
        width: 100px;
        text-align: center;
      }
    }
  }
}
</style>
